package com.qf.huigou.controller;

import com.qf.huigou.pojo.User;
import com.qf.huigou.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.8.0_131
 * @Author WangYiZhu
 * @Email 2641956765@qq.com
 * @Time 2022/12/09 11:19
 */
@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("login")
    @ResponseBody
    public Map<String,String> userLogin(String userName, String userPassword, HttpSession session){
       User user= userService.selectLogin(userName);
        Map<String,String> map=new HashMap<>();
        if (user==null){
            map.put("msg","用户名不存在");
            return map;
        }
        if (user!=null&&user.getUserPassword().equals(userPassword)){
            map.put("msg","success");
            session.setAttribute("userName",user.getUserName());
            session.setAttribute("USER",user);
        }else {
            map.put("msg","密码错误");
        }
        return map;
    }
}
